<?php
/*
 * Copyright (c) 2013 Eugene Kuzmenko
 *
 * Permission  is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in  the Software without restriction, including without limitation the rights
 * to  use,  copy,  modify,  merge, publish, distribute, sublicense, and/or sell
 * copies  of  the  Software,  and  to  permit  persons  to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The  above  copyright  notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE  SOFTWARE  IS  PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED,  INCLUDING  BUT  NOT  LIMITED  TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS  FOR  A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS  OR  COPYRIGHT  HOLDERS  BE  LIABLE  FOR  ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 * 
 * For more information, see <http://www.aljey.com>.
 */

namespace Al\Validation\Lib;

use Al\Core\Lib\Service;

/**
 * A class for all the validation adapters to extend.
 *
 * @author Eugene Kuzmenko <mail@aljey.com>
 */
abstract class AbstractValidatorAdapter {

  /**
   * @var bool A default setting for the "allow_blank" configuration directive.
   */
  protected $allowBlank = false;

  /**
   * @var string A default setting for the "invalid_message" configuration
   * directive.
   */
  protected $invalidMessage;

  /**
   * @var string A default setting for the "required_message" configuration
   * directive.
   */
  protected $requiredMessage;

  public function __construct() {
    $config = Service::get('config');
    $this->invalidMessage = $config->trans('error.INVALID');
    $this->requiredMessage = $config->trans('error.REQUIRED');
  }

  /**
   * Returns the current setting for the "allow_blank" configuration directive.
   *
   * @return bool Should a blank value be allowed?
   */
  public function getAllowBlank() {
    return $this->allowBlank;
  }

  /**
   * Returns the current setting for the "invalid_message" configuration
   * directive.
   *
   * @return string A textual explanation of why the validation's been failed.
   */
  public function getInvalidMessage() {
    return $this->invalidMessage;
  }

  /**
   * Returns the current setting for the "required_message" configuration
   * directive.
   *
   * @return string A textual explanation of why the validation's been failed.
   */
  public function getRequiredMessage() {
    return $this->requiredMessage;
  }

  /**
   * Checks the value.
   *
   * @param mixed $value [optional] A value to test.
   * @param array $options [optional] Any additional options that a validator may accept.
   * @return bool Does the value validate?
   */
  abstract public function validate($value = null, $options = array());

}